include("shared.lua")
surface.CreateFont("HUDNumber5",33,55,true,false,"SpawnPointsText",false,false)

local spawnusers = {}

function ENT:Initialize()
	if self:GetModel() == "models/error.mdl" then
		self:SetModel("models/props_combine/combine_mine01.mdl")
	end
end


local function GetUser( um )
	local ply = um:ReadEntity()
	local ent = um:ReadEntity()
	local handle = um:ReadBool()

	if handle then
		spawnusers[ ply ] = ent
		
	else
		spawnusers[ ply ] = nil
		
	end
end

usermessage.Hook("spawnpoint_user",GetUser)

function ENT:DrawUsers()

	local pos = self:GetPos() + Vector(0,0,40) //+ Self:GetRight() * 10
	local ang = EyeAngles()
	ang:RotateAroundAxis( ang:Forward(), 90 )
	ang:RotateAroundAxis( ang:Right(), 90 )

	cam.Start3D2D(pos , Angle( 0 , ang.y , ang.r) , 0.1)
		
		if LocalPlayer():GetEyeTraceNoCursor().Entity == self then
			surface.SetFont("SpawnPointsText")
			local x,y = surface.GetTextSize("Current Users are...")
			
			surface.SetDrawColor(30,30,30,210)
			surface.DrawRect( -x / 2 - 13 , 0 , x + 26 , y + 15 )

			surface.SetDrawColor(150,150,150,150)
			surface.DrawRect( -x / 2 - 5 , 8 , x + 10 , y )
			
	    	surface.SetTextColor( 0, 0, 0, 255 )
	    	surface.SetTextPos( -x / 2 , 8 ) 
	    	surface.DrawText( "Current Users are..." )
	    	
	    	local inc = 0
			for k,v in pairs(spawnusers) do
				if v == self then
					inc = inc + 1
					local x,y = surface.GetTextSize(k:Nick())
					local h = y + 15

					surface.SetDrawColor(30,30,30,210)
					surface.DrawRect( -x / 2 - 13 ,  h * inc , x + 26 , y + 15 )

					surface.SetDrawColor(150,150,150,150)
					surface.DrawRect( -x / 2 - 5 , h * inc + 7.5 , x + 10 , y )

					
					surface.SetTextPos(-x / 2 , h * inc + 8)
					surface.DrawText( k:Nick() )

					
	    			
	    		end
	    	end
	    end
	
	cam.End3D2D()
end

hook.Add("PostDrawTranslucentRenderables","SpawnPoints_DrawUsers",function() 
	for k,v in pairs( ents.GetAll() ) do
		if v.DrawUsers then
			v:DrawUsers()
		end
	end
end)


